﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BestBuy.DAL;
using System.IO;
namespace BestBuy.UserControl
{
    public partial class ProductInfoDetail : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Form.Attributes.Add("enctype", "multipart/form-data");
        }
        public void LoadCategory(int ID)
        {
            lbDanhMuc.Text = cDangSanPham.GetCategoryString(ID);
            HiddenCategory.Value = ID.ToString();
        }
        //load dữ liệu
        protected void DropDownList1_Load(object sender, EventArgs e)
        {
            DropDownList1.DataSource = cDonVi.getDonVi();
            DropDownList1.DataTextField = "TenDonVi";
            DropDownList1.DataValueField = "IDDonVi";
            DropDownList1.DataBind();
        }

        protected void DropDownList3_Load(object sender, EventArgs e)
        {
            DropDownList3.DataSource = cDonVi.getDonVi();
            DropDownList3.DataTextField = "TenDonVi";
            DropDownList3.DataValueField = "IDDonVi";
            DropDownList3.DataBind();
        }
        //get dữ liệu

        public int getIdCategory
        {
            get
            {
               return int.Parse(HiddenCategory.Value);
            }
        }

        public string getProductDetail
        {
            get
            {
                return txtProductDetail.Text;
            }
        }
        public string getProductName
        {
            get
            {
                return txtProductName.Text;
            }
        }
        public string getModel
        {
            get
            {
                return txtModel.Text;
            }
        }
        public string getKeyWord
        {
            get
            {
                return txtKeyword.Text;
            }
        }
        public string getDescription
        {
            get
            {
                return txtDescription.Text;
            }
        }
        public string getUrlPhoto
        { 
            get
            {
                return FileUpload1.FileName;
                //if (FileUpload1.HasFile)
                //{
                    
                //    str = Server.MapPath("~/Images/product/") +  FileUpload1.FileName;
                //    FileUpload1.SaveAs(Server.MapPath("~") + FileUpload1.FileName);   
                //    FileUpload1.SaveAs(str);
                //}             
            }
        }
        
        public string getUrlBrochoure
        {
            get
            {
                return upLoadBrochoure.FileName;
                //if (upLoadBrochoure.FileName != "")
                //{
                //    strFileName = Server.MapPath("upload\\" + upLoadBrochoure.FileName);
                //    upLoadBrochoure.PostedFile.SaveAs(strFileName);
                //}
                //FileUpload img = (FileUpload)upLoadBrochoure;
                //Byte[] imgbyte = null;
                //if (img.HasFile && img.PostedFile != null)
                //{
                //    HttpPostedFile File = upLoadBrochoure.PostedFile;
                //    //Create byte Array with file len
                //    imgbyte = new Byte[File.ContentLength];
                //    //force the control to load data in array
                //    File.InputStream.Read(imgbyte, 0, File.ContentLength);
                    
                //}
            }
        }
        public void setPhoto()
        {
            if (FileUpload1.HasFile)
            {                
                uploadPhoto = FileUpload1;
            }
            else
            {
                uploadPhoto= null;
            }
        }
        public void setBrochoure()
        {
            if (upLoadBrochoure.HasFile)
            {
                upload_Brochoure = upLoadBrochoure;
            }
            else
            {
                upload_Brochoure = null;
            }
        }
        public String getHinhAnh()
        {
            if (uploadPhoto!=null)
            {
                return uploadPhoto.FileName;
            }
            else {
                return "";
            }            
        }
        public String getTaiLieu()
        {
            if (upload_Brochoure!=null)
            {
                return upload_Brochoure.FileName;
            } 
            else
            {
                return "";
            }            
        }
        public void Savephoto()
        {
            if (uploadPhoto != null)
            {
                if (uploadPhoto.HasFile)
                {
                    String str = "";
                    str = Server.MapPath("~/Images/Product/") + uploadPhoto.FileName;
                    uploadPhoto.SaveAs(str);
                }
            }            
        }
        public void SaveBrochoure()
        {
            if (upload_Brochoure!=null)
            {
                if (upload_Brochoure.HasFile)
                {
                    String str = "";
                    str = Server.MapPath("~/Brochoure/") + upload_Brochoure.FileName;
                    upload_Brochoure.SaveAs(str);
                }
            }            
        }        
        public static FileUpload uploadPhoto = null;
        public static FileUpload upload_Brochoure = null;
        public string getDeliverTime
        {
            get
            {
                return StartTimeTextBox.Text;
            }
        }
        public string getSupplyingAbility
        {
            get
            {
                return EndTimeTextBox.Text + "/" + DropDownList1.SelectedItem.Text + "/" + DropDownList2.Text;
            }
        }
        
        public string getPlaceOfOrigin
        {
            get
            {
                return txtPlaceOfOrigin.Text;
            }
        }
        public string getMinimumOrder
        {
            get
            {
                return txtMinimumOrder.Text + "/" + DropDownList3.SelectedItem.Text;
            }
        }
        public int[] getPayment
        {
            get
            {
                int []array ={0,0,0,0};
                if (CheckBox1.Checked ==true)
                {
                    array[0] =1;
                }
                if (CheckBox2.Checked ==true)
                {
                    array[1]=1;
                }
                if (CheckBox3.Checked ==true)
                {
                    array[2] =1;
                }
                if (CheckBox4.Checked ==true)
                {
                    array[3]=1;
                }
                return array;
            }
        }
    }
}